package com.huishu.user.controller;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huishu.commons.pojo.Result;
import com.huishu.user.pojo.dto.BuoyDTO;
import com.huishu.user.pojo.model.BuoyDO;
import com.huishu.user.service.BuoyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author generator@ljj
 * @since 2023-04-22
 */
@RestController
@RequestMapping("/buoy")
public class BuoyController {

    @Autowired
    private BuoyService buoyService;

    @GetMapping("/findAll")
    public Result findAll() {
        return Result.success(buoyService.list(Wrappers.lambdaQuery(BuoyDO.class)
                .orderByAsc(BuoyDO::getSort)));
    }

    @PostMapping("/update")
    public Result modify(@RequestBody BuoyDTO buoyDTO) {
        return buoyService.handle(buoyDTO, 2);
    }

    @PostMapping("/updateIsShow")
    public Result updateIsShow(@RequestBody BuoyDTO buoyDTO) {
        LambdaUpdateWrapper<BuoyDO> uw = Wrappers.lambdaUpdate(BuoyDO.class)
                .set(BuoyDO::getIsShow, buoyDTO.getIsShow())
                .eq(BuoyDO::getId, buoyDTO.getId());
        return buoyService.update(uw) ? Result.success() : Result.fail();
    }
}
